// @FileName  :edit.c
// @Time      :2024/4/5 0:05
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>

struct node {
    int op, pos;
    char str[520], *nxt;
} his[99];

char *insert(struct node *his, char *cur) {
    char *res = (char *) malloc(520 * sizeof(char));
    strncpy(res, cur, his->pos);
    *(res + his->pos) = '\0';
    strcat(res, his->str);
    strcat(res, cur + his->pos);
//    printf("%s\n", res);
    return res;
}

char *delete(struct node *his, char *cur, int type) {//type 决定str是长度还是字符串
    char *res = (char *) malloc(520 * sizeof(char));;
    if (type) { //如果是字符串
        strncpy(res, cur, his->pos);
        *(res + his->pos) = '\0';
        strcat(res, cur + his->pos + strlen(his->str));
    } else {
        int cnt = 0;
        for (int i = 0; i < strlen(his->str); i++) cnt = cnt * 10 + his->str[i] - '0';
        strncpy(his->str, cur + his->pos, cnt);
        strncpy(res, cur, his->pos);
        *(res + his->pos) = '\0';
        strcat(res, cur + his->pos + cnt);
    }
//    printf("%s\n", res);
    return res;
}

int main() {
    setbuf(stdout, NULL);
    char *cur = (char *) malloc(520 * sizeof(char));
    fgets(cur, 520, stdin);
    int n;
    scanf("%d", &n);
    his[n].nxt = cur;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &his[i].op);
        if (his[i].op == 3) continue;
        scanf("%d %s", &his[i].pos, his[i].str);
    }
    for (int i = n; i > 0; i--) {
        if (his[i].op == 1)
            his[i - 1].nxt = delete(&his[i], cur, 1);
        else if (his[i].op == 2)
            his[i - 1].nxt = insert(&his[i], cur);
        else
            his[i - 1 > 0 ? i - 1 : 0].nxt = his[i].nxt;
        cur = his[i - 1].nxt;
    }
    getchar();
    while (1) {
        cur = his[n].nxt;
        scanf("%d", &his[++n].op);
        if (his[n].op == -1) break;
        if (his[n].op != 3) scanf("%d %s", &his[n].pos, his[n].str);
        if (his[n].op == 1)
            his[n].nxt = insert(&his[n], cur);
        else if (his[n].op == 2)
            his[n].nxt = delete(&his[n], cur, 0);
        else {
            n = n - 2 > 0 ? n - 2 : 0;
//            printf("undo: %s\n", his[n].nxt);
        }
    }
    printf("%s", cur);
}